<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>地图</title>
<style type="text/css">
html {
	height: 100%
}

body {
	height: 100%;
	margin: 0px;
	padding: 0px
}

#container {
	height: 100%
}
</style>
<script src="http://api.map.baidu.com/api?v=1.5&ak=170493a069b08faaba1a3ac49774fcc9"></script>
</head>

<body>
<div id="container"></div>
<script type="text/javascript"> 
var map = new BMap.Map("container");          // 创建地图实例  
var point = new BMap.Point(112.570975,37.844368);  // 创建点坐标(北京)  
var e_point = new BMap.Point(112.570975,37.844368);	//终点的经纬度
map.centerAndZoom(point, 15);       // 初始化地图，设置中心点坐标和地图级别
map.enableScrollWheelZoom(true);	//支持滚轮缩放
map.addControl(new BMap.NavigationControl());	//添加地图平移缩放控件
var opts = {
	position : e_point,    // 指定文本标注所在的地理位置
	offset   : new BMap.Size(16, -36)    //设置文本偏移量
}
var label = new BMap.Label("恒地大厦", opts);  // 创建文本标注对象
	label.setStyle({
		color : "red",
		fontSize : "14px",
		height : "26px",
		lineHeight : "26px",
		fontFamily:"微软雅黑"
	 });
	 map.addOverlay(label);//添加标注
//添加定位功能
var opts = {anchor: BMAP_ANCHOR_TOP_RIGHT,showAddressBar:false,enableAutoLocation:false};
var gl = new BMap.GeolocationControl(opts);
map.addControl(gl);
gl.location();
//定位成功处理函数
gl.addEventListener('locationSuccess',function(r){
	var p1 = new BMap.Point(r.point.lng,r.point.lat);
	var p2 = new BMap.Point(112.570975,37.844368);
	var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
	driving.search(p1, p2);
});
</script>
</body>
</html>
